package com.baiyichen.servlet;

import com.alibaba.fastjson.JSONArray;
import com.baiyichen.pojo.Books;
import com.baiyichen.service.BooksServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Author:BaiYiChen
 * Date:2022/3/2213:22
 */
@Controller
@RestController
@RequestMapping("/b")
public class BooksServlet {
  
  private BooksServiceImpl impl;
  @Autowired
  public void setImpl(BooksServiceImpl impl) {
    this.impl = impl;
  }
  
  @RequestMapping(value = "/sel.do",produces = "text/application;charset=utf-8")
  public String getBook(HttpServletRequest req, HttpServletResponse resp){
    List<Books> books = impl.getBooks();
    
    resp.addCookie(new Cookie("ac", "123456"));
  
    return JSONArray.toJSONString(books);
  }
}
